package handler

import (
	"github.com/gin-gonic/gin"
	"choujiang/common/models"
	"choujiang/common/utils"
	"choujiang/common/consts"
	"choujiang/box_server/service"
	"fmt"
)

func AwardGet(c *gin.Context) {
	form := c.Request.Form
	uniqueId := form.Get("uniqueId")
	user := model.GetUserByUniqueId(uniqueId)
	if user == nil {
		utils.Error(consts.ErrUserNotFound, c)
		return
	}
	ret := make(map[string]interface{})
	award, err := service.GetAward()
	if err != nil {
		fmt.Printf("service.AwardGet err:", err)
	}
	ret["data"] = award
	ret["cost"] = 200
	utils.JSON(ret, c)
}

func GetLottery(c *gin.Context) {
	form := c.Request.Form
	uniqueId := form.Get("uniqueId")
	user := model.GetUserByUniqueId(uniqueId)
	if user == nil {
		utils.Error(consts.ErrUserNotFound, c)
		return
	}
	uExtra := model.GetUserExtraByUid(user.Id)
	if uExtra.Point < 200 {
		utils.Error(consts.ErrNotEnoughPoint, c)
		return
	}
	award := service.GetLottery(user)

	utils.JSON(award, c)
}
